{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/huang/Documents/autowork_for_office/examples'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sys import path,platform\n",
    "match platform:\n",
    "    case \"linux\":\n",
    "        path.append(\"/home/huang/Documents/autowork_for_office\")\n",
    "    case \"darwin\":\n",
    "        path.append(\"/Users/huangzhiming/Documents/python学习/MSoffice的python使用/autowork_for_office\")\n",
    "    case \"win32\":\n",
    "        pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/home/huang/Documents/autowork_for_office/examples',\n",
       " '/home/huang/anaconda3/envs/use-auto-office/lib/python312.zip',\n",
       " '/home/huang/anaconda3/envs/use-auto-office/lib/python3.12',\n",
       " '/home/huang/anaconda3/envs/use-auto-office/lib/python3.12/lib-dynload',\n",
       " '',\n",
       " '/home/huang/anaconda3/envs/use-auto-office/lib/python3.12/site-packages',\n",
       " '/home/huang/Documents/autowork_for_office']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from docx import Document\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload \n",
    "%autoreload 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport docxes.utils\n",
    "from docxes.utils import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport docxes.editor\n",
    "from docxes.editor import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc=Document(\"/home/huang/Downloads/2023年新课标全国Ⅰ卷数学真题.docx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "paras = doc.paragraphs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "515"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(paras)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 测试函数get_result_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_result_index(paras,r\"\\W*?参考答案\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check get_result_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=get_result_index(paras,r\"^\\d+\\W*[\\.．]\\w+\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the ordinal number 4\n",
      "['1．已知集合']\n",
      "the ordinal number 16\n",
      "['2．已知']\n",
      "the ordinal number 24\n",
      "['3．已知向量']\n",
      "the ordinal number 35\n",
      "['4．设函数在区间上单调递减']\n",
      "the ordinal number 46\n",
      "['5．设椭圆的离心率分别为']\n",
      "the ordinal number 54\n",
      "['6．过点与圆相切的两条直线的夹角为']\n",
      "the ordinal number 87\n",
      "['7．记为数列的前项和']\n",
      "the ordinal number 114\n",
      "['8．已知']\n",
      "the ordinal number 130\n",
      "['9．有一组样本数据']\n",
      "the ordinal number 156\n",
      "['10．噪声污染问题越来越受到重视']\n",
      "the ordinal number 177\n",
      "['11．已知函数的定义域为']\n",
      "the ordinal number 208\n",
      "['12．下列物体中']\n",
      "the ordinal number 238\n",
      "['13．某学校开设了4门体育类选修课和4门艺术类选修课']\n",
      "the ordinal number 249\n",
      "['14．在正四棱台中']\n",
      "the ordinal number 261\n",
      "['15．已知函数在区间有且仅有3个零点']\n",
      "the ordinal number 273\n",
      "['16．已知双曲线的左']\n",
      "the ordinal number 301\n",
      "['17．已知在中']\n",
      "the ordinal number 323\n",
      "['18．如图']\n",
      "the ordinal number 357\n",
      "['19．已知函数']\n",
      "the ordinal number 398\n",
      "['20．设等差数列的公差为']\n",
      "the ordinal number 422\n",
      "['21．甲']\n",
      "the ordinal number 449\n",
      "['22．在直角坐标系中']\n"
     ]
    }
   ],
   "source": [
    "for k,v in answer.items():\n",
    "    print(\"the ordinal number %d\" %k)\n",
    "    print(v)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check get_target_set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'一、单选题', '三、填空题', '二、多选题', '四、解答题'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_target_set(paras,r\"[一二三四]、\\w{2}题\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check get_blocks_paras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from docxes.reg_constants import RE_QUESTION_STRS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=get_blocks_paras(paras,RE_QUESTION_STRS[0],r\"【答案】\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(answer)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check get_blocks_header"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=get_blocks_header(paras,RE_QUESTION_STRS,r\"【答案】\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------------------------------------------\n",
      "1．已知集合，，则（    ）\n",
      "A．\tB．\tC．\tD．\n",
      "----------------------------------------------------\n",
      "2．已知，则（    ）\n",
      "A．\tB．\tC．0\tD．1\n",
      "----------------------------------------------------\n",
      "3．已知向量，若，则（    ）\n",
      "A．\tB．\n",
      "C．\tD．\n",
      "----------------------------------------------------\n",
      "4．设函数在区间上单调递减，则的取值范围是（    ）\n",
      "A．\tB．\n",
      "C．\tD．\n",
      "----------------------------------------------------\n",
      "5．设椭圆的离心率分别为．若，则（    ）\n",
      "A．\tB．\tC．\tD．\n",
      "----------------------------------------------------\n",
      "6．过点与圆相切的两条直线的夹角为，则（    ）\n",
      "A．1\tB．\tC．\tD．\n",
      "----------------------------------------------------\n",
      "7．记为数列的前项和，设甲：为等差数列；乙：为等差数列，则（    ）\n",
      "A．甲是乙的充分条件但不是必要条件\n",
      "B．甲是乙的必要条件但不是充分条件\n",
      "C．甲是乙的充要条件\n",
      "D．甲既不是乙的充分条件也不是乙的必要条件\n",
      "----------------------------------------------------\n",
      "8．已知，则（    ）．\n",
      "A．\tB．\tC．\tD．\n",
      "----------------------------------------------------\n",
      "9．有一组样本数据，其中是最小值，是最大值，则（    ）\n",
      "A．的平均数等于的平均数\n",
      "B．的中位数等于的中位数\n",
      "C．的标准差不小于的标准差\n",
      "D．的极差不大于的极差\n",
      "----------------------------------------------------\n",
      "10．噪声污染问题越来越受到重视．用声压级来度量声音的强弱，定义声压级，其中常数是听觉下限阈值，是实际声压．下表为不同声源的声压级：\n",
      "已知在距离燃油汽车、混合动力汽车、电动汽车处测得实际声压分别为，则（    ）．\n",
      "A．\tB．\n",
      "C．\tD．\n",
      "----------------------------------------------------\n",
      "11．已知函数的定义域为，，则（    ）．\n",
      "A．\tB．\n",
      "C．是偶函数\tD．为的极小值点\n",
      "----------------------------------------------------\n",
      "12．下列物体中，能够被整体放入棱长为1（单位：m）的正方体容器（容器壁厚度忽略不计）内的有（    ）\n",
      "A．直径为的球体\n",
      "B．所有棱长均为的四面体\n",
      "C．底面直径为，高为的圆柱体\n",
      "D．底面直径为，高为的圆柱体\n",
      "----------------------------------------------------\n",
      "13．某学校开设了4门体育类选修课和4门艺术类选修课，学生需从这8门课中选修2门或3门课，并且每类选修课至少选修1门，则不同的选课方案共有        种（用数字作答）．\n",
      "----------------------------------------------------\n",
      "14．在正四棱台中，，则该棱台的体积为        ．\n",
      "----------------------------------------------------\n",
      "15．已知函数在区间有且仅有3个零点，则的取值范围是        ．\n",
      "----------------------------------------------------\n",
      "16．已知双曲线的左、右焦点分别为．点在上，点在轴上，，则的离心率为        ．\n",
      "----------------------------------------------------\n",
      "17．已知在中，．\n",
      "(1)求；\n",
      "(2)设，求边上的高．\n",
      "----------------------------------------------------\n",
      "18．如图，在正四棱柱中，．点分别在棱,上，．\n",
      "  \n",
      "(1)证明：；\n",
      "(2)点在棱上，当二面角为时，求．\n",
      "----------------------------------------------------\n",
      "19．已知函数．\n",
      "(1)讨论的单调性；\n",
      "(2)证明：当时，．\n",
      "----------------------------------------------------\n",
      "20．设等差数列的公差为，且．令，记分别为数列的前项和．\n",
      "(1)若，求的通项公式；\n",
      "(2)若为等差数列，且，求．\n",
      "----------------------------------------------------\n",
      "21．甲、乙两人投篮，每次由其中一人投篮，规则如下：若命中则此人继续投篮，若末命中则换为对方投篮．无论之前投篮情况如何，甲每次投篮的命中率均为0.6，乙每次投篮的命中率均为0.8．由抽签确定第1次投篮的人选，第1次投篮的人是甲、乙的概率各为0.5．\n",
      "(1)求第2次投篮的人是乙的概率；\n",
      "(2)求第次投篮的人是甲的概率；\n",
      "(3)已知：若随机变量服从两点分布，且，则．记前次（即从第1次到第次投篮）中甲投篮的次数为，求．\n",
      "----------------------------------------------------\n",
      "22．在直角坐标系中，点到轴的距离等于点到点的距离，记动点的轨迹为．\n",
      "(1)求的方程；\n",
      "(2)已知矩形有三个顶点在上，证明：矩形的周长大于．\n"
     ]
    }
   ],
   "source": [
    "for l in answer:\n",
    "    print(\"--------------------------\"*2)\n",
    "    for i in l:\n",
    "        print(paras[i].text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check get_blocks_tailer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=get_blocks_tailer(paras,RE_QUESTION_STRS[0],r\"【答案】\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------------------------------------------\n",
      "【答案】C\n",
      "【分析】\n",
      "方法一：由一元二次不等式的解法求出集合，即可根据交集的运算解出．\n",
      "方法二：将集合中的元素逐个代入不等式验证，即可解出．\n",
      "【详解】方法一：因为，而，\n",
      "所以．\n",
      "故选：C．\n",
      "方法二：因为，将代入不等式，只有使不等式成立，所以．\n",
      "故选：C．\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】A\n",
      "【分析】\n",
      "根据复数的除法运算求出，再由共轭复数的概念得到，从而解出．\n",
      "【详解】因为，所以，即．\n",
      "故选：A．\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】D\n",
      "【分析】\n",
      "根据向量的坐标运算求出，，再根据向量垂直的坐标表示即可求出．\n",
      "【详解】因为，所以，，\n",
      "由可得，，\n",
      "即，整理得：．\n",
      "故选：D．\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】D\n",
      "【分析】\n",
      "利用指数型复合函数单调性，判断列式计算作答.\n",
      "【详解】函数在R上单调递增，而函数在区间上单调递减，\n",
      "则有函数在区间上单调递减，因此，解得，\n",
      "所以的取值范围是.\n",
      "故选：D\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】A\n",
      "【分析】\n",
      "根据给定的椭圆方程，结合离心率的意义列式计算作答.\n",
      "【详解】由，得，因此，而，所以.\n",
      "故选：A\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】B\n",
      "【分析】\n",
      "方法一：根据切线的性质求切线长，结合倍角公式运算求解；方法二：根据切线的性质求切线长，结合余弦定理运算求解；方法三：根据切线结合点到直线的距离公式可得，利用韦达定理结合夹角公式运算求解.\n",
      "【详解】方法一：因为，即，可得圆心，半径，\n",
      "过点作圆C的切线，切点为，\n",
      "因为，则，\n",
      "可得，\n",
      "则，\n",
      "，\n",
      "即为钝角，\n",
      "所以；\n",
      "法二：圆的圆心，半径，\n",
      "过点作圆C的切线，切点为，连接，\n",
      "可得，则，\n",
      "因为\n",
      "且，则，\n",
      "即，解得，\n",
      "即为钝角，则，\n",
      "且为锐角，所以；\n",
      "方法三：圆的圆心，半径，\n",
      "若切线斜率不存在，则切线方程为，则圆心到切点的距离，不合题意；\n",
      "若切线斜率存在，设切线方程为，即，\n",
      "则，整理得，且\n",
      "设两切线斜率分别为，则，\n",
      "可得，\n",
      "所以，即，可得，\n",
      "则，\n",
      "且，则，解得.\n",
      "故选：B.\n",
      "    \n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】C\n",
      "【分析】\n",
      "利用充分条件、必要条件的定义及等差数列的定义，再结合数列前n项和与第n项的关系推理判断作答.，\n",
      "【详解】\n",
      "方法1，甲：为等差数列，设其首项为，公差为，\n",
      "则，\n",
      "因此为等差数列，则甲是乙的充分条件；\n",
      "反之，乙：为等差数列，即为常数，设为，\n",
      "即，则，有，\n",
      "两式相减得：，即，对也成立，\n",
      "因此为等差数列，则甲是乙的必要条件，\n",
      "所以甲是乙的充要条件，C正确.\n",
      "方法2，甲：为等差数列，设数列的首项，公差为，即，\n",
      "则，因此为等差数列，即甲是乙的充分条件；\n",
      "反之，乙：为等差数列，即，\n",
      "即，，\n",
      "当时，上两式相减得：，当时，上式成立，\n",
      "于是，又为常数，\n",
      "因此为等差数列，则甲是乙的必要条件，\n",
      "所以甲是乙的充要条件.\n",
      "故选：C\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】B\n",
      "【分析】\n",
      "根据给定条件，利用和角、差角的正弦公式求出，再利用二倍角的余弦公式计算作答.\n",
      "【详解】因为，而，因此，\n",
      "则，\n",
      "所以.\n",
      "故选：B\n",
      "【点睛】方法点睛：三角函数求值的类型及方法\n",
      "（1）“给角求值”：一般所给出的角都是非特殊角，从表面来看较难，但非特殊角与特殊角总有一定关系．解题时，要利用观察得到的关系，结合三角函数公式转化为特殊角的三角函数．\n",
      "（2）“给值求值”：给出某些角的三角函数值，求另外一些角的三角函数值，解题关键在于“变角”，使其角相同或具有某种关系．\n",
      "（3）“给值求角”：实质上也转化为“给值求值”，关键也是变角，把所求角用含已知角的式子表示，由所得的函数值结合该函数的单调区间求得角，有时要压缩角的取值范围．\n",
      "\n",
      "\n",
      "二、多选题\n",
      "----------------------------------------------------\n",
      "【答案】BD\n",
      "【分析】根据题意结合平均数、中位数、标准差以及极差的概念逐项分析判断.\n",
      "【详解】对于选项A：设的平均数为，的平均数为，\n",
      "则，\n",
      "因为没有确定的大小关系，所以无法判断的大小，\n",
      "例如：，可得；\n",
      "例如，可得；\n",
      "例如，可得；故A错误；\n",
      "对于选项B：不妨设，\n",
      "可知的中位数等于的中位数均为，故B正确；\n",
      "对于选项C：因为是最小值，是最大值，\n",
      "则的波动性不大于的波动性，即的标准差不大于的标准差，\n",
      "例如：，则平均数，\n",
      "标准差，\n",
      "，则平均数，\n",
      "标准差，\n",
      "显然，即；故C错误；\n",
      "对于选项D：不妨设，\n",
      "则，当且仅当时，等号成立，故D正确；\n",
      "故选：BD.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】ACD\n",
      "【分析】根据题意可知，结合对数运算逐项分析判断.\n",
      "【详解】由题意可知：，\n",
      "对于选项A：可得，\n",
      "因为，则，即，\n",
      "所以且，可得，故A正确；\n",
      "对于选项B：可得，\n",
      "因为，则，即，\n",
      "所以且，可得，\n",
      "当且仅当时，等号成立，故B错误；\n",
      "对于选项C：因为，即，\n",
      "可得，即，故C正确；\n",
      "对于选项D：由选项A可知：，\n",
      "且，则，\n",
      "即，可得，且，所以，故D正确；\n",
      "故选：ACD.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】ABC\n",
      "【分析】方法一：利用赋值法，结合函数奇偶性的判断方法可判断选项ABC，举反例即可排除选项D.\n",
      "方法二：选项ABC的判断与方法一同，对于D，可构造特殊函数进行判断即可.\n",
      "【详解】方法一：\n",
      "因为，\n",
      "对于A，令，，故正确.\n",
      "对于B，令，，则，故B正确.\n",
      "对于C，令，，则，\n",
      "令，\n",
      "又函数的定义域为，所以为偶函数，故正确，\n",
      "对于D，不妨令，显然符合题设条件，此时无极值，故错误.\n",
      "方法二：\n",
      "因为，\n",
      "对于A，令，，故正确.\n",
      "对于B，令，，则，故B正确.\n",
      "对于C，令，，则，\n",
      "令，\n",
      "又函数的定义域为，所以为偶函数，故正确，\n",
      "对于D，当时，对两边同时除以，得到，\n",
      "故可以设，则，\n",
      "当肘，，则，\n",
      "令，得；令，得；\n",
      "故在上单调递减，在上单调递增，\n",
      "因为为偶函数，所以在上单调递增，在上单调递减，\n",
      "  \n",
      "显然，此时是的极大值，故D错误.\n",
      "故选：.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】ABD\n",
      "【分析】\n",
      "根据题意结合正方体的性质逐项分析判断.\n",
      "【详解】对于选项A：因为，即球体的直径小于正方体的棱长，\n",
      "所以能够被整体放入正方体内，故A正确；\n",
      "对于选项B：因为正方体的面对角线长为，且，\n",
      "所以能够被整体放入正方体内，故B正确；\n",
      "对于选项C：因为正方体的体对角线长为，且，\n",
      "所以不能够被整体放入正方体内，故C不正确；\n",
      "对于选项D：因为，可知底面正方形不能包含圆柱的底面圆，\n",
      "如图，过的中点作，设，\n",
      "可知，则，\n",
      "即，解得，\n",
      "且，即，\n",
      "故以为轴可能对称放置底面直径为圆柱，\n",
      "若底面直径为的圆柱与正方体的上下底面均相切，设圆柱的底面圆心，与正方体的下底面的切点为，\n",
      "可知：，则，\n",
      "即，解得，\n",
      "根据对称性可知圆柱的高为，\n",
      "所以能够被整体放入正方体内，故D正确；\n",
      "故选：ABD.\n",
      "\n",
      "\n",
      "\n",
      "三、填空题\n",
      "----------------------------------------------------\n",
      "【答案】64\n",
      "【分析】\n",
      "分类讨论选修2门或3门课，对选修3门，再讨论具体选修课的分配，结合组合数运算求解.\n",
      "【详解】（1）当从8门课中选修2门，则不同的选课方案共有种；\n",
      "（2）当从8门课中选修3门，\n",
      "①若体育类选修课1门，则不同的选课方案共有种；\n",
      "②若体育类选修课2门，则不同的选课方案共有种；\n",
      "综上所述：不同的选课方案共有种.\n",
      "故答案为：64.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】/\n",
      "【分析】\n",
      "结合图像，依次求得，从而利用棱台的体积公式即可得解.\n",
      "【详解】如图，过作，垂足为，易知为四棱台的高，\n",
      "  \n",
      "因为，\n",
      "则，\n",
      "故，则，\n",
      "所以所求体积为.\n",
      "故答案为：.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】\n",
      "【分析】\n",
      "令，得有3个根，从而结合余弦函数的图像性质即可得解.\n",
      "【详解】\n",
      "因为，所以，\n",
      "令，则有3个根，\n",
      "令，则有3个根，其中，\n",
      "结合余弦函数的图像性质可得，故，\n",
      "\n",
      "故答案为：.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】/ \n",
      "【分析】\n",
      "方法一：利用双曲线的定义与向量数积的几何意义得到关于的表达式，从而利用勾股定理求得，进而利用余弦定理得到的齐次方程，从而得解.\n",
      "方法二：依题意设出各点坐标，从而由向量坐标运算求得，，将点代入双曲线得到关于的齐次方程，从而得解；\n",
      "【详解】\n",
      "方法一：\n",
      "依题意，设，则，\n",
      "在中，，则，故或（舍去），\n",
      "所以，，则，\n",
      "故，\n",
      "所以在中，，整理得，\n",
      "故.\n",
      "\n",
      "方法二:\n",
      "依题意，得，令，\n",
      "因为，所以，则，\n",
      "又，所以，则，\n",
      "又点在上，则，整理得，则，\n",
      "所以，即，\n",
      "整理得，则，解得或，\n",
      "又，所以或（舍去），故.\n",
      "故答案为：.\n",
      "【点睛】\n",
      "关键点睛：双曲线过焦点的三角形的解决关键是充分利用双曲线的定义，结合勾股定理与余弦定理得到关于的齐次方程，从而得解.\n",
      "\n",
      "\n",
      "四、解答题\n",
      "----------------------------------------------------\n",
      "【答案】(1)\n",
      "(2)6\n",
      "\n",
      "【分析】（1）根据角的关系及两角和差正弦公式，化简即可得解；\n",
      "（2）利用同角之间的三角函数基本关系及两角和的正弦公式求,再由正弦定理求出，根据等面积法求解即可.\n",
      "【详解】（1），\n",
      "，即，\n",
      "又，\n",
      "，\n",
      "，\n",
      "，\n",
      "即，所以，\n",
      ".\n",
      "（2）由（1）知，，\n",
      "由，\n",
      "由正弦定理，，可得，\n",
      "，\n",
      ".\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】(1)证明见解析；\n",
      "(2)1\n",
      "\n",
      "【分析】（1）建立空间直角坐标系，利用向量坐标相等证明；\n",
      "（2）设，利用向量法求二面角，建立方程求出即可得解.\n",
      "【详解】（1）\n",
      "以为坐标原点，所在直线为轴建立空间直角坐标系，如图，\n",
      "  \n",
      "则，\n",
      "，\n",
      "，\n",
      "又不在同一条直线上，\n",
      ".\n",
      "（2）\n",
      "设，\n",
      "则，\n",
      "设平面的法向量，\n",
      "则，\n",
      "令 ，得，\n",
      "，\n",
      "设平面的法向量，\n",
      "则，\n",
      "令 ，得，\n",
      "，\n",
      "，\n",
      "化简可得，，\n",
      "解得或，\n",
      "或，\n",
      ".\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】(1)答案见解析\n",
      "(2)证明见解析\n",
      "\n",
      "【分析】（1）先求导，再分类讨论与两种情况，结合导数与函数单调性的关系即可得解；\n",
      "（2）方法一：结合（1）中结论，将问题转化为的恒成立问题，构造函数，利用导数证得即可.\n",
      "方法二：构造函数，证得，从而得到，进而将问题转化为的恒成立问题，由此得证.\n",
      "【详解】（1）因为，定义域为，所以，\n",
      "当时，由于，则，故恒成立，\n",
      "所以在上单调递减；\n",
      "当时，令，解得，\n",
      "当时，，则在上单调递减；\n",
      "当时，，则在上单调递增；\n",
      "综上：当时，在上单调递减；\n",
      "当时，在上单调递减，在上单调递增.\n",
      "（2）方法一：\n",
      "由（1）得，，\n",
      "要证，即证，即证恒成立，\n",
      "令，则，\n",
      "令，则；令，则；\n",
      "所以在上单调递减，在上单调递增，\n",
      "所以，则恒成立，\n",
      "所以当时，恒成立，证毕.\n",
      "方法二：\n",
      "令，则，\n",
      "由于在上单调递增，所以在上单调递增，\n",
      "又，\n",
      "所以当时，；当时，；\n",
      "所以在上单调递减，在上单调递增，\n",
      "故，则，当且仅当时，等号成立，\n",
      "因为，\n",
      "当且仅当，即时，等号成立，\n",
      "所以要证，即证，即证，\n",
      "令，则，\n",
      "令，则；令，则；\n",
      "所以在上单调递减，在上单调递增，\n",
      "所以，则恒成立，\n",
      "所以当时，恒成立，证毕.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】(1)\n",
      "(2)\n",
      "\n",
      "【分析】（1）根据等差数列的通项公式建立方程求解即可；\n",
      "（2）由为等差数列得出或，再由等差数列的性质可得，分类讨论即可得解.\n",
      "【详解】（1），，解得，\n",
      "，\n",
      "又，\n",
      "，\n",
      "即，解得或（舍去），\n",
      ".\n",
      "（2）为等差数列，\n",
      "，即，\n",
      "，即，解得或，\n",
      "，，\n",
      "又，由等差数列性质知，，即，\n",
      "，即，解得或（舍去）\n",
      "当时，，解得，与矛盾，无解；\n",
      "当时，，解得.\n",
      "综上，.\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】(1)\n",
      "(2)\n",
      "(3)\n",
      "\n",
      "【分析】\n",
      "（1）根据全概率公式即可求出；\n",
      "（2）设，由题意可得，根据数列知识，构造等比数列即可解出；\n",
      "（3）先求出两点分布的期望，再根据题中的结论以及等比数列的求和公式即可求出．\n",
      "【详解】（1）记“第次投篮的人是甲”为事件，“第次投篮的人是乙”为事件，\n",
      "所以，\n",
      ".\n",
      "（2）设，依题可知，，则\n",
      "，\n",
      "即，\n",
      "构造等比数列，\n",
      "设，解得，则，\n",
      "又，所以是首项为，公比为的等比数列，\n",
      "即．\n",
      "（3）因为，，\n",
      "所以当时，，\n",
      "故．\n",
      "【点睛】本题第一问直接考查全概率公式的应用，后两问的解题关键是根据题意找到递推式，然后根据数列的基本知识求解．\n",
      "\n",
      "----------------------------------------------------\n",
      "【答案】(1)\n",
      "(2)见解析\n",
      "\n",
      "【分析】（1）设，根据题意列出方程，化简即可；\n",
      "（2）法一：设矩形的三个顶点，且，分别令，，且，利用放缩法得，设函数，利用导数求出其最小值，则得的最小值，再排除边界值即可.\n",
      "法二：设直线的方程为，将其与抛物线方程联立，再利用弦长公式和放缩法得，利用换元法和求导即可求出周长最值，再排除边界值即可.\n",
      "法三：利用平移坐标系法，再设点，利用三角换元再对角度分类讨论，结合基本不等式即可证明.\n",
      "【详解】（1）设,则，两边同平方化简得，\n",
      "故.\n",
      "（2）法一：设矩形的三个顶点在上,且，易知矩形四条边所在直线的斜率均存在，且不为0，\n",
      "  \n",
      "则,令，\n",
      "同理令，且，则，\n",
      "设矩形周长为,由对称性不妨设，，\n",
      "则，易知\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "则令,\n",
      "令，解得，\n",
      "当时，，此时单调递减，\n",
      "当，，此时单调递增，\n",
      "则，\n",
      "故,即.\n",
      "当时,,且，即时等号成立，矛盾，故,\n",
      "得证.\n",
      "法二：不妨设在上，且，\n",
      "  \n",
      "依题意可设，易知直线，的斜率均存在且不为0，\n",
      "则设,的斜率分别为和，由对称性，不妨设，\n",
      "直线的方程为，\n",
      "则联立得，\n",
      "，则\n",
      "则，\n",
      "同理，\n",
      "\n",
      "\n",
      "令，则，设，\n",
      "则，令，解得，\n",
      "当时，，此时单调递减，\n",
      "当，，此时单调递增，\n",
      "则，\n",
      "，\n",
      "但，此处取等条件为，与最终取等时不一致，故.\n",
      "法三：为了计算方便,我们将抛物线向下移动个单位得抛物线,\n",
      "矩形变换为矩形,则问题等价于矩形的周长大于.\n",
      "设 , 根据对称性不妨设 . \n",
      "则 , 由于 , 则 .\n",
      "由于 , 且  介于  之间, \n",
      "则 . 令 ,\n",
      ",则,从而\n",
      "\n",
      "故\n",
      "①当时,\n",
      "\n",
      "②当  时,由于,从而,\n",
      "从而又,\n",
      "故,由此\n",
      "\n",
      "\n",
      "，\n",
      "当且仅当时等号成立，故，故矩形周长大于.\n",
      "  .\n",
      "【点睛】关键点睛：本题的第二个的关键是通过放缩得，同时为了简便运算，对右边的式子平方后再设新函数求导，最后再排除边界值即可.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for l in answer:\n",
    "    print(\"--------------------------\"*2)\n",
    "    for i in l:\n",
    "        print(paras[i].text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "paras[4]._element.getparent().remove(paras[4]._element)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "515"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(paras)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc.save(\"changed.docx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/huang/Documents/autowork_for_office/examples'"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'4．设函数在区间上单调递减，则的取值范围是（\\xa0\\xa0\\xa0\\xa0）'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paras[35].text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from docxes.editor import change_question_number\n",
    "\n",
    "\n",
    "change_question_number(paras[35],1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1．设函数在区间上单调递减，则的取值范围是（\\xa0\\xa0\\xa0\\xa0）'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paras[35].text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">\n",
      "  <w:pPr>\n",
      "    <w:shd w:val=\"clear\" w:color=\"auto\" w:fill=\"auto\"/>\n",
      "    <w:spacing w:line=\"360\" w:lineRule=\"auto\"/>\n",
      "    <w:jc w:val=\"both\"/>\n",
      "    <w:textAlignment w:val=\"center\"/>\n",
      "  </w:pPr>\n",
      "  <w:r>\n",
      "    <w:t>1</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>．设函数</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1068\" type=\"#_x0000_t75\" alt=\"eqIddde116e3d5a7483b4d53dca54edbbd03\" style=\"width:60.69pt;height:18.47pt\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId84\" o:title=\"eqIddde116e3d5a7483b4d53dca54edbbd03\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1068\" DrawAspect=\"Content\" ObjectID=\"_44\" r:id=\"rId85\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>在区间</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1069\" type=\"#_x0000_t75\" alt=\"eqId7160d93f92089ef36f3dab809d3114b8\" style=\"width:23.75pt;height:17.59pt\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId86\" o:title=\"eqId7160d93f92089ef36f3dab809d3114b8\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1069\" DrawAspect=\"Content\" ObjectID=\"_45\" r:id=\"rId87\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>上单调递减，则</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1070\" type=\"#_x0000_t75\" alt=\"eqId0a6936d370d6a238a608ca56f87198de\" style=\"width:8.79pt;height:9.52pt\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId88\" o:title=\"eqId0a6936d370d6a238a608ca56f87198de\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1070\" DrawAspect=\"Content\" ObjectID=\"_46\" r:id=\"rId89\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>的取值范围是（</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:rPr>\n",
      "      <w:rFonts w:ascii=\"Times New Roman\" w:eastAsia=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:cs=\"Times New Roman\"/>\n",
      "      <w:kern w:val=\"0\"/>\n",
      "      <w:sz w:val=\"24\"/>\n",
      "      <w:szCs w:val=\"24\"/>\n",
      "    </w:rPr>\n",
      "    <w:t>    </w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>）</w:t>\n",
      "  </w:r>\n",
      "</w:p>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(paras[35]._element.xml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">\n",
      "  <w:pPr>\n",
      "    <w:shd w:val=\"clear\" w:color=\"auto\" w:fill=\"auto\"/>\n",
      "    <w:tabs>\n",
      "      <w:tab w:val=\"left\" w:pos=\"4156\"/>\n",
      "    </w:tabs>\n",
      "    <w:spacing w:line=\"360\" w:lineRule=\"auto\"/>\n",
      "    <w:ind w:left=\"300\"/>\n",
      "    <w:jc w:val=\"both\"/>\n",
      "    <w:textAlignment w:val=\"center\"/>\n",
      "  </w:pPr>\n",
      "  <w:r>\n",
      "    <w:t>C．</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1073\" type=\"#_x0000_t75\" alt=\"eqId589ed49839c4dc0b033431d88a4c1f94\" style=\"width:24.65pt;height:17.99pt;mso-position-horizontal-relative:page;mso-position-vertical-relative:page\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId94\" o:title=\"eqId589ed49839c4dc0b033431d88a4c1f94\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1073\" DrawAspect=\"Content\" ObjectID=\"_49\" r:id=\"rId95\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:tab/>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>D．</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1074\" type=\"#_x0000_t75\" alt=\"eqIdcda591d3909af06eabf6b37c65bfe571\" style=\"width:33.43pt;height:17.55pt\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId96\" o:title=\"eqIdcda591d3909af06eabf6b37c65bfe571\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1074\" DrawAspect=\"Content\" ObjectID=\"_50\" r:id=\"rId97\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "</w:p>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(paras[37]._element.xml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<docx.text.run.Run at 0x74aca1007aa0>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paras[37].add_run(\"hello,world!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hello,world!'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "paras[37].runs[-1].text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">\n",
      "  <w:pPr>\n",
      "    <w:shd w:val=\"clear\" w:color=\"auto\" w:fill=\"auto\"/>\n",
      "    <w:tabs>\n",
      "      <w:tab w:val=\"left\" w:pos=\"4156\"/>\n",
      "    </w:tabs>\n",
      "    <w:spacing w:line=\"360\" w:lineRule=\"auto\"/>\n",
      "    <w:ind w:left=\"300\"/>\n",
      "    <w:jc w:val=\"both\"/>\n",
      "    <w:textAlignment w:val=\"center\"/>\n",
      "  </w:pPr>\n",
      "  <w:r>\n",
      "    <w:t>C．</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1073\" type=\"#_x0000_t75\" alt=\"eqId589ed49839c4dc0b033431d88a4c1f94\" style=\"width:24.65pt;height:17.99pt;mso-position-horizontal-relative:page;mso-position-vertical-relative:page\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId94\" o:title=\"eqId589ed49839c4dc0b033431d88a4c1f94\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1073\" DrawAspect=\"Content\" ObjectID=\"_49\" r:id=\"rId95\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:tab/>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:t>D．</w:t>\n",
      "  </w:r>\n",
      "  <w:r>\n",
      "    <w:object>\n",
      "      <v:shape id=\"_x0000_i1074\" type=\"#_x0000_t75\" alt=\"eqIdcda591d3909af06eabf6b37c65bfe571\" style=\"width:33.43pt;height:17.55pt\" o:oleicon=\"f\" o:ole=\"\">\n",
      "        <v:imagedata r:id=\"rId96\" o:title=\"eqIdcda591d3909af06eabf6b37c65bfe571\"/>\n",
      "      </v:shape>\n",
      "      <o:OLEObject Type=\"Embed\" ProgID=\"Equation.DSMT4\" ShapeID=\"_x0000_i1074\" DrawAspect=\"Content\" ObjectID=\"_50\" r:id=\"rId97\"/>\n",
      "    </w:object>\n",
      "  </w:r>\n",
      "</w:p>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(paras[37]._element.xml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "move_elements(paras[37].runs[-1],paras[37].runs[0],next=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "insert_run(paras[37],0,\"hi! huang.\",next=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "delete_element(paras[37].runs[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba as jb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<generator object Tokenizer.cut at 0x7c4ef0187b60>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jb.cut(\"北京的 天气真好啊！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['北京', '的', ' ', '天气', '真好', '啊', '！']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/huang/anaconda3/envs/use-auto-office/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import pycorrector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading data from https://deepspeech.bj.bcebos.com/zh_lm/zh_giga.no_cna_cmn.prune01244.klm\n",
      "2953396224/2953395058 [==============================] - 916s 0us/step\n",
      "{'source': '我爱中华', 'target': '我爱中华', 'errors': []}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 单句文本纠错\n",
    "sentence = '我爱中华'\n",
    "corrector = pycorrector.Corrector()\n",
    "corrected_sentence=corrector.correct(sentence)\n",
    "print(corrected_sentence)  # 输出：'我爱你国'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'source': '少先队员因该为老人让坐', 'target': '少先队员应该为老人让座', 'errors': [('因该', '应该', 4), ('坐', '座', 10)]}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "sentences =  '少先队员因该为老人让坐'\n",
    "corrected_sentences = corrector.correct(sentences)\n",
    "print(corrected_sentences)  # 输出：['我爱你国', '少先队员应该为老人让座']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['穿流不息', 2, 6, 'proper'], ['因该', 11, 13, 'word'], ['坐', 17, 18, 'char']]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 文本错误检测\n",
    "idx_errors = corrector.detect('人群穿流不息，少先队员因该为老人让坐')\n",
    "print(idx_errors)  # 输出：[['穿流不息', 2, 6, 'proper'], ['因该', 11, 13, 'word'], ['坐', 17, 18, 'char']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'source': '穿流不息', 'target': '川流不息', 'errors': [('穿流不息', '川流不息', 0)]}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrector.correct('穿流不息')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'source': '遇到一位很美的女士和我疗天',\n",
       " 'target': '遇到一位很美的女士和我聊天',\n",
       " 'errors': [('疗天', '聊天', 11)]}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrector.correct('遇到一位很美的女士和我疗天')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "auto-office-work",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
